{extend name='admin@public/content'}

{block name='style'}
<style>
    .param-table-list {
        overflow: auto;
        max-height: 500px;
        position: relative;
        overflow-y: scroll;
    }

    .param-input-td {
        position: relative;
        padding: 0 !important;
    }

    .param-input-td.one {
        width: 15%;
    }

    .param-input-td.thr {
        width: 10%;
        text-align: center;
    }

    .param-input-td.four {
        width: 10%;
    }
    .param-input-td.five {
        width: 5%;
    }
    .param-input-td.six {
        width: 10%;
    }

    .param-input-td input {
        /*padding-left: 50px;*/
        border: none !important;
    }
</style>

{/block}

{block name='content'}
<form onsubmit="return false;" action="" data-auto="true" method="post" class='form-horizontal layui-form' style='padding-top:20px'>
    {if isset($vo['id'])}
    <input type="hidden" name="id" value="{$vo.id}">
    {/if}
    <div class="form-group">
        <label class="col-sm-2 control-label">所属栏目：<span class="nowrap"></span></label>
        <div class='col-sm-8'>
            <select name="pid" id="">
                {foreach $cate as $v}
                <option {if isset($vo['id']) && $vo.pid==$v.id}selected{/if} value="{$v.id}">{$v.title}</option>
                {/foreach}
            </select>
            <p class="help-block"></p>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label label-required">封面图片：<span class="nowrap"></span></label>
        <div class='col-sm-8'>
            <img data-tips-image style="height:auto;max-width:200px" src="{$vo.thumb ?: '__STATIC__/theme/img/image.png'}"/>
            <input type="hidden" name="thumb" onchange="$(this).prev('img').attr('src', this.value)" value="{$vo.thumb ?: ''}" class="layui-input">
            <a class="btn btn-link" data-file="one" data-uptype="" data-width="" data-height="" data-type="png,jpg,jpeg" data-field="thumb">上传图片</a>
            <p class="help-block"></p>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">标题：<span class="nowrap"></span></label>
        <div class='col-sm-8'>
            <input type="text" name="title" title="请输入新闻标题" required placeholder="请输入新闻标题" value="{$vo.title ?: ''}" class="layui-input">
            <p class="help-block"></p>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">作者：<span class="nowrap"></span></label>
        <div class='col-sm-8'>
            <input type="text" name="author" title="请输入作者" required placeholder="请输入作者名称" value="{$vo.author ?: 'ADMIN'}" class="layui-input">
            <p class="help-block"></p>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">来源：<span class="nowrap"></span></label>
        <div class='col-sm-8'>
            <input type="text" name="source" title="请输入来源" required placeholder="请输入来源" value="{$vo.source ?: '本站'}" class="layui-input">
            <p class="help-block"></p>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">发布日期：<span class="nowrap"></span></label>
        <div class='col-sm-8'>
            <input autocomplete="off" type="text" name="create_at" title="请输入" required placeholder="请输入" value="{$vo.create_at|default=date('Y-m-d')|date='Y-m-d'}" class="layui-input birth">
            <p class="help-block"></p>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">封面描述：<span class="nowrap"></span></label>
        <div class='col-sm-8'>
            <textarea name="desc" class="layui-textarea">{$vo.desc|default=''}</textarea>
            <p class="help-block"></p>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">外链：<span class="nowrap"></span></label>
        <div class='col-sm-8'>
            <div class="param-table-list">
                <table class="layui-table margin-none">
                    <tbody class="param-table-list">
                    {if !empty($vo.link)}
                    {foreach $vo.link as $k=>$v}
                    <tr class="transition">
                        <td class="param-input-td four nowrap">
                            <button data-file="one" data-type="png,jpg,jpeg" data-field="link[{$k}][thumb]" type="button" class="layui-btn layui-btn-sm" style="height:38px;line-height:38px;width:100%">上传图标</button>
                        </td>
                        <td class="param-input-td five nowrap text-center">
                            <img data-tips-image style="height:auto;max-height:38px;" src="{$v['thumb'] ?: '__STATIC__/theme/img/image.png'}"/>
                            <input type="hidden" name="link[{$k}][thumb]" onchange="$(this).prev('img').attr('src', this.value)" value="{$v['thumb']}" class="layui-input">
                        </td>

                        <td class="param-input-td two nowrap">
                            <input name="link[{$k}][value]" autocomplete="off" value="{$v.value}" placeholder="请输入" class="layui-input">
                        </td>
                        <td class="param-input-td six nowrap text-center">
                            <input type="checkbox" {if isset($v.status)&&$v.status=='on'}checked{/if} name="link[{$k}][status]" lay-skin="switch" lay-text="显示|隐藏">
                        </td>
                        <td class="param-input-td thr nowrap text-center">
                            <a class="color-desc del">删除</a>
                            <a class="color-desc up">上移</a>
                            <a class="color-desc down">下移</a>
                        </td>
                    </tr>
                    {/foreach}
                    {else}
                    <tr class="transition">
                        <td class="param-input-td four nowrap">
                            <button data-file="one" data-type="png,jpg,jpeg" data-field="link[0][thumb]" type="button" class="layui-btn layui-btn-sm" style="height:38px;line-height:38px;width:100%">上传图标</button>
                        </td>
                        <td class="param-input-td five nowrap text-center">
                            <img data-tips-image style="height:auto;max-height:38px;" src="__STATIC__/theme/img/image.png"/>
                            <input type="hidden" name="link[0][thumb]" onchange="$(this).prev('img').attr('src', this.value)" value="" class="layui-input">
                        </td>
                        <td class="param-input-td two nowrap">
                            <input name="link[0][value]" autocomplete="off" placeholder="请输入链接，注意带上http或https" class="layui-input" >
                        </td>
                        <td class="param-input-td six nowrap text-center">
                            <input type="checkbox" name="link[0][status]" lay-skin="switch" lay-text="显示|隐藏">
                        </td>
                        <td class="param-input-td thr nowrap text-center">
                            <a class="color-desc del">删除</a>
                            <a class="color-desc up">上移</a>
                            <a class="color-desc down">下移</a>
                        </td>
                    </tr>
                    {/if}
                    </tbody>
                </table>
            </div>
            <table class="layui-table">
                <tr>
                    <td class="text-center notselect padding-none border-none">
                        <button type="button" class="layui-btn full-width layui-btn-primary add">添加属性</button>
                    </td>
                </tr>
            </table>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">新闻正文：<span class="nowrap"></span></label>
        <div class='col-sm-8'>
            <textarea name="content" required placeholder="请输入" class="layui-textarea">{$vo.content ?: ''}</textarea>
            <p class="help-block"></p>
        </div>
    </div>

    <div class="hr-line-dashed"></div>

    <div class="col-sm-8 col-sm-offset-2">
        <div class="layui-form-item text-left">
            <button class="layui-btn" type="submit">保存</button>
        </div>
    </div>
</form>

{/block}
{block name="script"}
<script>
    window.form.render();
    laydate.render({elem: '.birth',type:'date'});
    //富文本
    require(['ckeditor'],function () {
        window.createEditor('[name="content"]', {height: 500});
    })
    var key;
    $(function () {
        key = $('.param-table-list .transition').length-1;
    })
    $('.add').on('click',function () {
        key++;
        var html_str = `<tr class="transition">
                        <td class="param-input-td four nowrap">
                            <button data-file="one" data-type="png,jpg,jpeg" data-field="link[${key}][thumb]" type="button" class="layui-btn layui-btn-sm" style="height:38px;line-height:38px;width:100%">上传图标</button>
                        </td>
                        <td class="param-input-td five nowrap text-center">
                            <img data-tips-image style="height:auto;max-height:38px;" src="__STATIC__/theme/img/image.png"/>
                            <input type="hidden" name="link[${key}][thumb]" onchange="$(this).prev('img').attr('src', this.value)" value="" class="layui-input">
                        </td>

                        <td class="param-input-td two nowrap">
                            <input name="link[${key}][value]" autocomplete="off" placeholder="请输入"  class="layui-input" >
                        </td>
                        <td class="param-input-td six nowrap text-center">
                            <input type="checkbox" name="link[${key}][status]" lay-skin="switch" lay-text="显示|隐藏">
                        </td>
                        <td class="param-input-td thr nowrap text-center">
                            <a class="color-desc del">删除</a>
                            <a class="color-desc up">上移</a>
                            <a class="color-desc down">下移</a>
                        </td>
                    </tr>`;
        $('tbody.param-table-list').append(html_str);
        form.render();
    })

    $('tbody.param-table-list').on('click','.del',function () {
        $(this).parents('.transition').remove();
    })

    $('tbody.param-table-list').on('click','.up',function () {
        var parentsDiv = $(this).parents(".transition");
        var prev = parentsDiv.prev();
        if(prev.html()!=undefined){
            //prev.before(parentsDiv);
            prev.fadeOut("fast",function(){
                $(this).before(parentsDiv);
            }).fadeIn();
        }
    })

    $('tbody.param-table-list').on('click','.down',function () {
        var parentsDiv = $(this).parents(".transition");
        var next = parentsDiv.next();
        if(next.html()!=undefined){
            //next.after(parentsDiv);
            next.fadeOut("fast",function(){
                $(this).after(parentsDiv);
            }).fadeIn();
        }
    })
</script>
{/block}